import { defineConfig } from "vitepress";
import {
  componentPreview,
  containerPreview,
} from "@vitepress-demo-preview/plugin";
import { join } from "node:path";

export default defineConfig({
  title: "leisure-lib",
  description: "vue3 Lib库",
  lastUpdated: true,
  vite: {
    server: {
      port: 3004,
      proxy: {
        "/api": {
          target: "http://localhost:3005",
          changeOrigin: true,
          rewrite: (path) => path.replace("/api", ""),
        },
      },
    },
    resolve: {
      alias: [
        {
          find: "@",
          replacement: join(__dirname, "/"),
        },
        {
          find: "leisure-lib/dist/style/index.less",
          replacement: join(__dirname, "..", "..", "style", "index.less"),
        },
        {
          find: "leisure-lib",
          replacement: join(__dirname, "..", "..", "src", "index.ts"),
        },
        {
          find: /^@leisure-lib\/(.+)$/,
          replacement: join(
            __dirname,
            "..",
            "..",
            "packages",
            "$1",
            "index.ts"
          ),
        },
      ],
    },
  },
  head: [["link", { rel: "icon", href: "/icon.svg" }]],
  themeConfig: {
    siteTitle: "leisure-lib",
    logo: "/icon.svg",
    search: {
      provider: "local",
    },
    editLink: {
      pattern: "https://www.npmjs.com/package/leisure-lib",
    },
    nav: [
      {
        text: "首页",
        link: "/",
      },
      {
        text: "指南",
        link: "/views/guide/why",
      },
      {
        text: "组件",
        link: "/views/components/icon",
        activeMatch: "/views/components/",
      },
      {
        text: "工具方法",
        link: "/views/utils/watermark",
        activeMatch: "/views/utils/",
      },
    ],
    sidebar: {
      "/views/guide/": [
        { text: "是什么", link: "/views/guide/why" },
        { text: "快速开始", link: "/views/guide/how" },
        { text: "样式管理", link: "/views/guide/style" },
      ],
      "/views/components/": [
        {
          text: "PC端组件",
          items: [
            { text: "icon", link: "/views/components/icon" },
            { text: "button", link: "/views/components/button" },
            { text: "loading", link: "/views/components/loading" },
            { text: "modal", link: "/views/components/modal" },
            { text: "table", link: "/views/components/table" },
            { text: "lightwave", link: "/views/components/lightwave" },
            { text: "fliqo", link: "/views/components/fliqo" },
            { text: "area", link: "/views/components/area" },
          ],
        },
      ],
      "/views/utils/": [{ text: "watermark", link: "/views/utils/watermark" }],
    },
    footer: {
      message: "Released under the MIT License.",
      copyright: "Copyright © 2024-present zhilang.zhang",
    },
    socialLinks: [
      { icon: "npm", link: "https://www.npmjs.com/package/leisure-lib" },
    ],
  },
  markdown: {
    theme: {
      light: "vitesse-light",
      dark: "vitesse-dark",
    },
    lineNumbers: true,
    config(md) {
      md.use(componentPreview);
      md.use(containerPreview);
    },
  },
});
